<?php

namespace App\Models\Wanggui;

use App\Models\BaseModel;
use App\Models\Traits\KfUid;
use Illuminate\Database\Eloquent\Factories\HasFactory;

class WangguiSearchDotModel extends BaseModel
{
    protected $table = 'wanggui_search_dots';

    protected $fillable = [
        'id',
        'wgNumber',
        'province',
        'city',
        'district',
        'provinceCode',
        'cityCode',
        'districtCode',
        'type',
        'address',
    ];

    public $timestamps = false;



    public function search($text, $cityCode): array
    {
        $data = [];
        self::query()
            //->whereRaw("MATCH({$column}) AGAINST ('{$text}')")
            ->where('address', 'like', "%{$text}%")
            ->where('cityCode', $cityCode)
            ->get()
            ->map(function ($q) use (&$data){
                if (isset($data[$q->type])) {
                    $data[$q->type][] = $q->wgNumber;
                } else {
                    $data[$q->type] = [$q->wgNumber];
                }
            })->toArray();
        return $data;
    }


}
